package com.sxt.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.sxt.model.EasyUIData;
import com.sxt.model.Menu;
import com.sxt.service.GoodsAttributeService;
import com.sxt.service.GoodsCatService;
import com.sxt.service.GoodsService;

@RestController
@RequestMapping("/goods")
public class GoodsController {

	@Autowired
	private GoodsCatService gcService;
	
	@Autowired
	private GoodsService gService;
	
	@Autowired
	private GoodsAttributeService gaService;
	
	@GetMapping("/cats") 
	public List<Menu> loadMenu(@RequestParam(defaultValue="0")Short pid){
		return gcService.loadMenuByPId(pid);
		
	}
	
	@GetMapping("/cats/")
	public List<Menu> loadAllMenu(){
		return gcService.loadAllMenu();
		
	}
   
	@RequestMapping("/")
	public EasyUIData getAllGoods(@RequestParam(defaultValue="1")Integer page,@RequestParam(defaultValue="30")Integer size) {
		return gService.queryAll(page, size);
		
	}
	
	@RequestMapping("/attr")
	public EasyUIData getAllGoodsAttr(@RequestParam(defaultValue="1")Integer page,@RequestParam(defaultValue="30")Integer size) {
		return gaService.findAll(page, size);
		
	}

}
